<template>
  <div class="user-info">
    <div class="info-view">
      <div class="info-pic">
        <img :src="userInfo.userPhoto?data.userPhoto:require('../../assets/images/man.png')" alt="" class="info-avatar">
      </div>
      <div class="info-cont">
        <p class="info-username">{{userInfo.nickName}}</p>
        <p class="info-balance">
          账户余额：
          <span class="info-balance-count">{{userInfo.accountBalance}}</span>
          屋币
          <router-link to="/index/recharge">
            <span class="info-recharge">立即充值</span>
          </router-link>
        </p>
      </div>
    </div>
    <div class="shelf-view">
      <p class="shelf-title">
        <span class="title-left">我的书架</span>
        <router-link to="/index/user/favorites">
          <span class="title-right">全部收藏 ></span>
        </router-link>
      </p>
      <c-user-book-list :bookList="bookShelf"/>
    </div>
  </div>
</template>

<script>
import cUserBookList from '../../components/user/UserBookList.vue';

export default {
  components:{
    cUserBookList
  },
  data(){
    return{
      userInfo:{},
      bookShelf:[]
    }
  },
  created(){
    this.getUserInfo();
    this.listBookShelf();
  },
  methods:{
    getUserInfo(){
      this.$http.postForm('/user/userInfo', null, res=>{
        this.userInfo = res;
        this.$cookies.set("nickname", res.nickName, 0);
      });
    },
    listBookShelf(){
      this.$http.postForm('/user/listBookShelfByPage', {limit:5}, res=>{
        this.bookShelf = res.list;
      });
    }
  }
}
</script>

<style lang='scss' scoped>
.user-info {
  padding: 0 25px;
  .info-view {
    padding: 20px 0;
    .info-pic {
      display: inline-block;
      width: 100px;
      .info-avatar {
        width: 80px;
        height: 80px;
      }
    }
    .info-cont {
      vertical-align: top;
      display: inline-block;
      width: calc(100% - 100px);
      .info-username {
        line-height: 30px;
        font-size: 20px;
      }
      .info-balance {
        font-size: 12px;
        .info-balance-count {
          color: $base-color;
        }
        .info-recharge {
          display: inline-block;
          border-radius: 3px;
          width: 60px;
          line-height: 20px;
          margin-left: 10px;
          background-color: $base-color;
          color: #fff;
          text-align: center;
        }
      }
    }
  }
  .shelf-view {
    .shelf-title {
      line-height: 30px;
      .title-left {
        color: #666;
        font-weight: bold;
      }
      .title-right {
        font-size: 12px;
        float: right;
      }
    }
  }
}
</style>